import React, {Component} from 'react';
import {Route, Switch, Link, Redirect} from 'react-router-dom';
import {Menu} from 'antd';
const {SubMenu} = Menu;

const deepCreateMenu = (child) => {
  return child.map ((vl, i) => {
    if (vl.children || Array.isArray(vl) ) {
      return (
        <SubMenu key={vl.path} title={vl.label}>
          {deepCreateMenu(vl.children || vl)}
        </SubMenu>
      );
    } else {
      return (
        <Menu.Item key={vl.path}>
          {vl.render && <Link to={vl.path}>{vl.label}</Link>}
          {!vl.render && <span>{vl.label}</span>}
        </Menu.Item>
      );
    }
  })
}

export default props => {
  const {child ,mode="inline"} = props;
  return (
    <React.Fragment>
      {child.length === 0 && <div>暂无数据信息</div>}
      <Menu className="routerMenu" defaultOpenKeys={['sub1']} mode={mode}>
        {deepCreateMenu(child)}
      </Menu>
    </React.Fragment>
  );
};
